package 算法.leetcode.offer;

/**
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 *
 *  
 *
 * 示例 1：
 *
 * 输入：s = "We are happy."
 * 输出："We%20are%20happy."
 *
 * @author lchenglong
 * @date 2022/3/21
 */
public class Offer05 {
    public String replaceSpace(String s) {
        char[] array = s.toCharArray();
        int len = array.length;
        StringBuilder sb = new StringBuilder();
        for (char c : array){
            if (c == ' '){
                sb.append("%20");
            }else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
